package demo

import (
	"fmt"
	"github.com/go-playground/validator/v10"
	"time"
)

type RequestLogin struct {
	Username string `form:"username" json:"username" xml:"username" binding:"required"`
	Password string `form:"password" json:"password" xml:"password" binding:"required"`
}

type RequestForm struct {
	Username string   `form:"username" json:"username" xml:"username" binding:"required"`
	Password string   `form:"password" json:"password" xml:"password" binding:"required"`
	Hobby    []string `form:"hobby"  json:"hobby" xml:"hobby" binding:"required"`
}

type Person struct {
	Id   int    `uri:"id" binding:"required"`
	Name string `uri:"name" binding:"required"`
}

type Booking struct {
	CheckIn  time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`
	CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn" time_format:"2006-01-02"`
}

func BookableDate(fl validator.FieldLevel) bool {
	date, ok := fl.Field().Interface().(time.Time)
	if ok {
		today := time.Now()
		if today.After(date) {
			return false
		}
	}
	return true
}

type User struct {
	Username string `form:"user_name" validate:"required"`
	Tagline  string `form:"tag_line" validate:"required,lt=10"`
	Tagline2 string `form:"tag_line2" validate:"required,gt=1"`
}


type User1 struct {
	Id   int
	Name string
	Age  int
}

func (u User1) ReflectCallFunc() {
	fmt.Println("Allen.Wu ReflectCallFunc")
}

func (u User1) ReflectCallFuncHasArgs(name string, age int) {
	fmt.Println("ReflectCallFuncHasArgs name: ", name, ", age:", age, "and origal User.Name:", u.Name)
}

func (u User1) ReflectCallFuncNoArgs() {
	fmt.Println("ReflectCallFuncNoArgs")
}